/*
 * @lc app=leetcode.cn id=1544 lang=javascript
 *
 * [1544] 整理字符串
 */

// @lc code=start
/**
 * @param {string} s
 * @return {string}
 */
var makeGood = function (s) {
  if (s.length < 2) return s;

  let stack = [];
  for( const cur of s) {
    const peek = stack[stack.length - 1] || '';
    // ✨关键点：如何判断一个小写、另一个大写
    cur !== peek && cur.toUpperCase() === peek.toUpperCase() ? stack.pop() : stack.push(cur);
  }

  return stack.join('');
};
// @lc code=end
